package com.funfei.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.funfei.entity.User;
import com.funfei.service.UserService;

@Controller
public class IndexController {

	@Autowired
	private UserService userService;
	@RequestMapping(value={"index",""},method=RequestMethod.GET)
	public String index(Model model) {
		model.addAttribute("user", new User());
		return "index";
	}

	@RequestMapping(value={"index",""},method=RequestMethod.POST)
	public String index(@Valid User user,BindingResult bindingResult,HttpServletRequest request/*,@RequestParam("rememberMe")boolean rememberMe,@RequestParam("verifyCode")String verifyCode*/){
		String rememberMe= request.getParameter("rememberMe");
		String verifyCode=request.getParameter("verifyCode");
		if(bindingResult.hasErrors()){
			return "/index";
		}
		userService.findAll();
		return "redirect:manage/index";
	}
	
    @RequestMapping(value = "/json1"  ,method = RequestMethod.GET)  
    public @ResponseBody  Object create() throws Exception {  
         System.out.println("ddddddd");
         List<User> userlist =userService.findAll(); 
        return userlist;  
    }
    @RequestMapping("/pdf")
    public String helloPDF(){
        return "helloPDF";
    }
}
